package com.fire.response;

/**
 * ClassName: ResponseCodeEnum
 * Package: org.common.response
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2024/3/10 - 11:01
 * @Version: v1.0
 */

import lombok.Getter;

/**
 * 统一响应枚举值
 */
@Getter
public enum ResponseCodeEnum {
    //客户端错误
    BAD_REQUEST(400,"请求错误！"),
    UNAUTHORIZED(401,"身份信息不合法"),
    FORBIDDEN(403,"无权限，请重新登录"),
    NOT_FOUND(404,"请求资源不存在"),

    //成功
    SUCCESS(200,"请求成功"),

    //业务代码
    SYSTEM_ERROR(500,"系统错误"),
    MACHINE_EXITS(1001,"机器已存在！添加失败"),
    TOKEN_EXPIRE(1002,"登录过期！"),
    LENGTH_ERROR(1003,"机器编号长度不符合，最长18位！"),
    UN_SUPPORT_DELETE(1004,"激活状态无法删除！请修改状态"),
    DATA_NOT_EXITS(1005,"机器数据不存在！"),
    MACHINE_NOT_FOUND(1006,"机器未添加，数据修改失败！"),
    NOTICE_NOT_FOUND(1008,"消息已丢失！"),
    ADMIN_NOT_FOUND(1010,"管理员不存在！"),
    PASSWORD_ERROR(1010,"密码错误！"),
    SENT_ERROR(1011,"发送失败！");


    /**
     * 响应码
     */
    private final int code;

    /**
     * 响应消息
     */
    private final String message;

    /**
     * 如何定义一个通用的枚举类
     * 举值-->构造-->遍历
     */

    /**
     * 构造
     * @param code
     * @param message
     * @return
     */
    ResponseCodeEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 遍历
     * @param code
     * @return
     */
    public static  ResponseCodeEnum getResponseCodeEnum(int code) {
        for (ResponseCodeEnum responseCodeEnum : ResponseCodeEnum.values()) {
            if (responseCodeEnum.getCode() == code) {
                return responseCodeEnum;
            }
        }
        return null;
    }
}
